package com.xue.tools;

public class StringTest {
    public static void main(String[] args) {
          //test01();
        test02();
    }
    /**
     * 字符串的存储
     */
    private static void test02(){
        int i = 10; // 10 就是常量
        // 定义一个字符串
        String str00 = "小明"; // 此处 创建了 1个
        String str01 = "小明"; // 创建了 1个对象（常量池中的元素不重复）
        // 如果只有下面一行代码执行的话，请问在该行代码之后在内存中创建了 2个对象
        String str10 = new String("小明"); // 创建了 2个对象
        String str11 = new String("小明"); // 创建了 3个对象

        System.out.println("str00 == str10::"+(str00 == str10));
        System.out.println("str00 == str01::"+(str00 == str01));
        System.out.println("str11 == str10::"+(str11 == str10));
        System.out.println("str00 == str11::"+(str00 == str11));
    }
    /**
     * String类常用方法：indexOf
     */
    private static void test01(){
        String str0 = "jkdafjlbk|asdjl,kfjlk|asd,389048923,jsdffjsdkalfj9o23";
        System.out.println("原始字符串："+str0);
        System.out.println("a的位置：："+str0.indexOf('a'));

        System.out.println("substring截取字符串：");
        System.out.println(""+str0.substring(3));
        System.out.println(""+str0.substring(str0.indexOf('a')));
        System.out.println(""+str0.substring(3,5));
        //System.out.println("aaa"+str0.substring(13,-2));

        System.out.println("字符串分割：");
        String[] strs = str0.split(",");
        for (String str : strs) {
            System.out.println(str);
        }

        System.out.println("字符串分割2：");
        String[] strs2 = str0.split("[|]");
        for (int i = 0; i < strs2.length; i++) {
            System.out.println(strs2[i]);
        }
        // indexOf
        System.out.println("查找指定下标的字符："+str0.indexOf(97,'b'));

        int  i  = str0.compareTo("zabc");
        System.out.println("compareto:::"+i);

        String newStr0 = str0.replace("asd","###");
        System.out.println("Old:::"+str0);
        System.out.println("New:::"+newStr0);
    }
}